-
Notifications
You must be signed in to change notification settings - Fork 46.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change string refs in function component message #18031
Conversation
This should refer to string refs specifically. The forwardRef part doesn't make any sense in this case. I think this was just an oversight.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit dbadcd6:
|
Wait, don't you still need to wrap a function component with Edit: nvm, seems like that's just a different error altogether. |
@@ -307,7 +307,7 @@ | |||
"306": "Element type is invalid. Received a promise that resolves to: %s. Lazy element type must resolve to a class or function.%s", | |||
"307": "Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)", | |||
"308": "Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo().", | |||
"309": "Function components cannot have refs. Did you mean to use React.forwardRef()?", | |||
"309": "Function components cannot have string refs. We recommend using useRef() instead. Learn more about using refs safely here: https://fb.me/react-strict-mode-string-ref", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update this doc to mention useRef?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems legit.
This should refer to string refs specifically. The forwardRef part doesn't make any sense in this case. I think this was just an oversight. This case is when a string ref is used from a function component, not on a function component.